#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
HiAgent Chat SDK 异常定义模块

定义了SDK中使用的各种异常类型，用于更好的错误处理和调试。
"""


class HiAgentException(Exception):
    """HiAgent SDK 基础异常类"""
    
    def __init__(self, message: str, error_code: str = None, details: dict = None):
        super().__init__(message)
        self.message = message
        self.error_code = error_code
        self.details = details or {}
    
    def __str__(self):
        if self.error_code:
            return f"[{self.error_code}] {self.message}"
        return self.message


class APIException(HiAgentException):
    """API调用异常"""
    
    def __init__(self, message: str, status_code: int = None, response_data: dict = None):
        super().__init__(message)
        self.status_code = status_code
        self.response_data = response_data or {}
    
    def __str__(self):
        if self.status_code:
            return f"API Error [{self.status_code}]: {self.message}"
        return f"API Error: {self.message}"


class AuthenticationException(HiAgentException):
    """认证异常 - API Key无效或过期"""
    pass


class ValidationException(HiAgentException):
    """参数验证异常"""
    pass


class NetworkException(HiAgentException):
    """网络连接异常"""
    pass


class ConversationNotFoundException(HiAgentException):
    """会话不存在异常"""
    pass


class MessageNotFoundException(HiAgentException):
    """消息不存在异常"""
    pass


class WorkflowException(HiAgentException):
    """工作流执行异常"""
    pass


class RateLimitException(HiAgentException):
    """请求频率限制异常"""
    pass